/***************************************************************************

  Capcom System QSound(tm)
  ========================

  Original MAME Driver by Paul Leaman (paul@vortexcomputing.demon.co.uk)
        and Miguel Angel Horna (mahorna@teleline.es)

  Port to SMSE2K by unknownfile, 2009

  A 16 channel stereo sample player.

  QSpace position is simulated by panning the sound in the stereo space.

  Register
  0  xxbb   xx = unknown bb = start high address
  1  ssss   ssss = sample start address
  2  pitch
  3  unknown (always 0x8000)
  4  loop offset from end address
  5  end
  6  master channel volume
  7  not used
  8  Balance (left=0x0110  centre=0x0120 right=0x0130)
  9  unknown (most fixed samples use 0 for this register)

  Many thanks to CAB (the author of Amuse), without whom this probably would
  never have been finished.

  If anybody has some information about this hardware, please send it to me
  to mahorna@teleline.es or 432937@cepsz.unizar.es.
  http://teleline.terra.es/personal/mahorna

***************************************************************************/

#include "smse2kincludes.h"
#include "SoundDeviceFactory.h"
#include "qsound.h"

/***************************************************************************
		Channel controls (seperate from the main CQSound class)
***************************************************************************/
void CQSoundChannel::RenderSample(CAudioBuffer* left, CAudioBuffer* right) {

}

void CQSoundChannel::Write(UINT8 data) {

};


int CQSound::Init(int sr, unsigned int clock) {
	this->frq_ratio = 16.0;

	/* Create pan table */
	for (int i=0; i<33; i++)
	{
		this->pan_table[i]=(int)((256/5.6569) * sqrt((double)i));
	}

	this->samplerate_native = clock / 166;
	this->samplerate_output = sr;

	// initialize outputs
	outputs[0] = new CAudioBuffer(samplerate_native,samplerate_output);
	outputs[1] = new CAudioBuffer(samplerate_native,samplerate_output);

	// Lock the chip and inform the user.
	locked = 1;
	Msg("QSound: Initialized but device locked. Send a ROM over.\n");
	return 0; // No errors
}

UINT8 CQSound::Read(UINT64 addr) {
	return 0x80; // Leaving this as-is even though it's a bit of a hack
}

int CQSound::GetRomSlotCount() {
	return 1;
}

void CQSound::SetRom(int slot, CMemory* rom) {

	sample_rom = rom;
	sample_rom_length = rom->GetSize();

	locked = 0;
	Msg("QSound: ROM recieved, device unlocked.\n");
}

void CQSound::Shutdown() {
	
}

void CQSound::Reset(void) {

}

int CQSound::Buffer(short ** buf, int length) {
	return 0; // go away i'm still writing this
}

void CQSound::Write(UINT64 offset, UINT8 data) {

}

/***********************************************
			Rendering
************************************************/





// QSound Device Factory
SOUND_FACTORY("QSound",1,CQSound);